//************************************************************
//    > File Name: vector.cpp
//    > Author: davis
//    > Mail:  
//    > Created Time: 2017年03月20日 17:50:08
//***********************************************************

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){

	vector<int> v= {
		10,20,30
	};
	auto it = v.emplace(v.begin()+1,100);
	for(auto& x: v)
		cout<<' '<<x;
	cout<<endl;               //10,100,20,30

	v.emplace(it,200);
	for(auto& x: v)
		cout<<' '<<x;
	cout<<endl;              //10,200,100,20,30

	vector<int> v1;
	v1.push_back(6);
	while(v1.back()!=0)
		v1.push_back(v1.back()-1);
	cout<<"v1 contains:";
	for(int i=0;i<v1.size();++i)
		cout<<" "<<v1[i];      //6 5 4 3 2 1 0
	cout<<endl;
	v1.erase(v1.begin()+1,v1.begin()+3);
	cout<<"after erase v1 ,v1 is :"; 
	for(auto& c:v1)
		cout<<c<<" "; //6 3 2 1 0
	cout<<"v1.front is "<<v1.front()<<"v1.back is "<<v1.back()<<endl; //6 0
	int arr[]={5,4};
	v1.insert(v1.begin()+1,arr,arr+2);
	cout<<"after insert v1,v1 is :";
	for(auto& c:v1)
		cout<<c<<" ";  //6 5 4 3 2 1 0
	cout<<endl;
	vector<int> v1_1=v1;
	cout<<"after v1_1=v1mv1_1 is ";
	for(auto it=v1_1.begin();it!=v1_1.end();++it)
		cout<<*it<<" ";  //6 5 4 3 2 1 0
	cout<<endl;
		

	vector<int> v2={
		1,2,3,4,5,6
	};
	cout<<"v2 begin rbegin cbegin:";
	for(auto it=v2.begin();it!=v2.end();++it){
		*it = *it+1;
		cout<<*it<<" ";       //2 3 4 5 6 7
	}
	cout<<endl;
	for(auto it=v2.rbegin();it!=v2.rend();++it)
		cout<<*it<<" ";      //7 6 5 4 3 2 
	cout<<endl;
	for(auto it=v2.cbegin();it!=v2.cend();++it){
	////	*it = *it -1; cbegin is const_iterator,can not modify the comtents it point to
		cout<<*it<<" ";        //2 3 4 5 6 7 
	}
	cout<<endl;
	v2.clear();
	cout<<"after v2.clear,v2.size is "<<v2.size()<<endl;   //0
	int myints[]={1,3,5,7,9};
	v2.assign(myints+1,myints+3);
	cout<<"after assign v2 is ";
	for(auto& c:v2)
		cout<<c<<" ";     //3 5 
	cout<<endl;


	vector<int> v3={
		100,200
	};
	v3.push_back(300);
	cout<<"v3 is ";
	for(vector<int>::iterator it=v3.begin();it!=v3.end();++it)
		cout<<*it<<" ";         //100 200 300
	cout<<endl;
	int sum (0);
	while(!v3.empty()){
		sum+=v3.back();
		v3.pop_back();
	}
	cout<<"v3.size is "<<v3.size()<<" sum is "<<sum<<endl;  //0 600
}

/******************
 10 100 20 30
  10 200 100 20 30
  v1 contains: 6 5 4 3 2 1 0
  after erase v1 ,v1 is :6 3 2 1 0 v1.front is 6v1.back is 0
  after insert v1,v1 is :6 5 4 3 2 1 0
  after v1_1=v1mv1_1 is 6 5 4 3 2 1 0
  v2 begin rbegin cbegin:2 3 4 5 6 7
  7 6 5 4 3 2
  2 3 4 5 6 7
  after v2.clear,v2.size is 0
  after assign v2 is 3 5
  v3 is 100 200 300
  v3.size is 0 sum is 600

**********************************/
